﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading.Tasks;
using Quartz;
using JinfuyuanProject.Repository;
using JinfuyuanProject.Entity;

namespace JinfuyuanProject.Jobs
{
    public class TestJob : IJob
    {



 
            private readonly IHomeRepository _homeRepository;

            public TestJob(IHomeRepository homeRepository)
            {
                _homeRepository = homeRepository;
            }

            public async Task Execute(IJobExecutionContext context)
            {
            const int targetHomeId = 1; // 要更新的Home记录ID

            try
            {
                // 获取目标Home对象
                Home home = await _homeRepository.GetModelAsync(targetHomeId);

                if (home != null)
                {
                    home.Area = (Convert.ToInt32(home.Area)+1).ToString(); // 增加1平方米

                    // 保存更新后的Home对象
                    await _homeRepository.UpdateAsync(home);
                }
                else
                {
                    System.Diagnostics.Trace.TraceError($"未找到ID为 {targetHomeId} 的Home记录.");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError($"Area增加失败: {ex.Message}");
            }
        }

        
    }
}
